package cn.edu.scau.cmi.wujiaxian.exercise11;

import java.awt.Color;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JColorChooser;
import javax.swing.JFrame;


public class WindowColor extends JFrame implements ActionListener{
	
	private static final long serialVersionUID = -8930213189512814290L;
	JButton button;
	
	public WindowColor() {
		button = new JButton("打开颜色对话框");
		button.addActionListener(this);
		setLayout(new FlowLayout());
		add(button);
		setVisible(true);
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
	}

	@Override
	public void actionPerformed(ActionEvent e) {
		Color newColor = JColorChooser.showDialog(this, "调色板", getContentPane().getBackground());
		if (newColor != null) {
			getContentPane().setBackground(newColor);
		}
		
	}
	
}
